package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseEnum;
import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.base.util.SrbAssert;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.pojo.entity.vo.LendInfoVO;
import com.atguigu.srb.core.service.LendService;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("/admin/core/lend")
public class AdminLendController {
    @Resource
    LendService lendService;

    @ApiOperation("放款")
    @PutMapping("/makeLoan/{id}")
    public ResponseVo makeLoan(@PathVariable("id")Long id){
        lendService.makeLoan(id);
        return ResponseVo.ok();
    }

    @ApiOperation("查询标的列表")
    @GetMapping
    public ResponseVo list(){
        List<Lend> lends = lendService.getLends();
        return ResponseVo.ok().data("items",lends);
    }


    @ApiOperation("标的发布")
    @PutMapping("/publish/{id}")
    public ResponseVo publish(@PathVariable("id")Long id){
        Lend lend = new Lend();
        lend.setId(id);
        lend.setPublishDate(new Date());
        lend.setStatus(1);//1为募资中
        lend.setCheckTime(new Date());
        lend.setCheckAdminId(1L);
        boolean b = lendService.updateById(lend);
        SrbAssert.AssertTrue(b, ResponseEnum.ERROR);
        return ResponseVo.ok().message("发布成功");
    }

    @ApiOperation("查询标的详情")
    @GetMapping("{id}")
    public ResponseVo getById(@PathVariable("id")Long id){
        LendInfoVO lendInfoVO = lendService.getLendInfoVOById(id);
        return ResponseVo.ok().data("item",lendInfoVO);
    }
}

